<template>
    <!--章节选择-->

    <div @click.stop
         class="ChapterList">
        <el-tree :highlight-current=true
                 :default-expand-all=true
                 :data="infoZHANGJIE"
                 @node-click="handleNodeClick"></el-tree>
    </div>
</template>


<script>
    import {mapGetters, mapActions} from 'vuex';
    import store from '../store/'


    import Vue from 'Vue'
    export default {
        name: "ChapterList",
        computed: mapGetters([
            'infoZHANGJIE',
            'infoKESHI'
        ]),
        components: {},
        data() {
            return {
                //                treeList: store.getters.infoZHANGJIE,
            }
        },
        methods: {
            handleNodeClick(data) {
                $('.layui-layer.layui-layer-tips.layer-anim').remove()
                var _this = this;
//                console.log(data)
                if (data.children.length === 0 && data.FatherID != 0) {
                    //更新当前章节名称
                    store.state.mutations.configJIAOCAI.ZHANGJIE = data.label
                    //设置当前章节ID
                    store.state.mutations.confirmZHANGJIEID = data.id
                    //关闭章节选择框
                    store.state.mutations.showJIAOCAI.ZHANGJIE = false;

//                    选择章节后默认选中第一课时，跳转至选课界面
//                    this.$http.get(('api/lession/steps?id=' + val.ID + '&sk=' + store.state.mutations.getToken)).then(function (res) {
//                        store.state.mutations.lessionSteps = res.data.data
//                    })


                    //请求获取课时列表
                    this.$http.get(('api/lession/period?id=' + store.state.mutations.confirmZHANGJIEID + '&sk=' + store.state.mutations.getToken)).then(function (res) {
                        store.state.mutations.infoKESHI = res.data.data

                        if(store.state.mutations.infoKESHI.length == 0){
                            store.state.mutations.configJIAOCAI.KESHI = "暂无课时"
                            store.state.mutations.infoKESHI = []
                            store.state.mutations.NoKeshiData = true
                        }else {

                            window.LessionID = res.data.data[0].ID

                            _this.$http.get(('api/lession/steps?id=' + res.data.data[0].ID + '&sk=' + store.state.mutations.getToken)).then(function (res) {
                                store.state.mutations.lessionSteps = res.data.data
                                store.state.mutations.NoKeshiData = false
                                store.state.mutations.configJIAOCAI.KESHI = "第"+res.data.data[0].ClassPeriod+"课时"
                            })
                        }
                        _this.$router.push('/home/XK')
                    })


                }
            }
        }
    }
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
    @import '../assets/css/public.scss';

    div.ChapterList {
        position: absolute;
        left: 0;
        bottom: 60px;
        right: 0;
        margin: auto;
        width: 900px;
        max-height: 600px;
        overflow-x: hidden;
        background: #fff;
        margin: 0 auto;
        box-shadow: $boxShadow;
    }

    .ChapterList::-webkit-scrollbar {
        width: 0px
    }
</style>